<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>对原型的重新认知</title>
  </head>
  <body>
    <script>
      function Person(name, age) {
        this.name = name;
        this.age = age;
      }

      var p1 = new Person("Alice", 12);
      console.log(p1);

      /* 在一个已存在的对象构造器中是不能添加新的属性的 */
      /*  Person.say = function(){
          console.log(this.name);
      } */

      /*
       *在定义构造器后还想动态的为对象添加属性和方法要添加到原型中
       */

       Person.prototype.score = 100;
       Person.prototype.func = function () {
           console.log(this.name);
         }

         console.log(p1.score);
         p1.func();

      /* 
      var per ={
          name: "Tom"
      }

      console.log(per.name);
      per.age =12;
      console.log(per.age); */
    </script>
  </body>
</html>
